import MockServer from './util/MockServer.js';

// ************************************************************************
// ************************************************************************
//
//
// PLEASE FEEL FREE TO EXAMINE THE CODE HERE, BUT MODIFYING CODE IN THE
// SERVICES FOLDER IS OUTSIDE THE BOUNDS OF THE EXERCISE.
//
// 
// ************************************************************************
// ************************************************************************


const data = {
    '1': [{
        auto_optimizer_id: '1',
        auto_optimizer_explanation: 'People in Austin, Boulder and Portland tend to click your ad more often than people in other cities. Consider confining your campaign to these regions.'
    },{
        auto_optimizer_id: '2',
        auto_optimizer_explanation: 'Ads for this campaign perform particularly poorly in Houston, consider excluding it from your advertising campaign.'
    }]
};

export default class CampaignGeoRecommendationService {
    // Dismiss a recommendation.
    static dismissRecommendation(campaignId, recommendationId) {
        return MockServer.request(() => {
            const recommendations = data[campaignId];

            data[campaignId] = recommendations.filter(recommendation => {
                return recommendation.auto_optimizer_id !== recommendationId;
            });

            return recommendationId;
        });
    }

    // Get a subset of the recommendations for the specified ID.
    static getRecommendations(campaignId, startIndex, count) {
        return MockServer.request(() => {
            const recommendations = data[campaignId] || [];

            return recommendations.slice(startIndex, startIndex+count);
        });
    }

    static getAllRecommendations(campaignId) {
        return MockServer.request(() => {
            return data[campaignId] || [];
        });
    }
}